<template>
  <div class="content">
    <manager-view
      v-if="editStatus"
      :show-initiate="false"
      :show-pause="false"
      :show-report="false"
      :show-done="false"
      :show-roll="false"
      :show-qualified-warehousing="false"
      :show-waste-storage="false"
      :show-receive="false"
      :show-get="false"
      :show-first="false"
      :show-quit="false"
      :show-reworke="true"
      :show-save="false"
      :disable-save="disableSave"
      :disable-copy="disableCopy"
      :disable-submit="disableSubmit"
      :disable-cancel="disableCancel"
      :disable-check="disableCheck"
      :disable-un-check="disableUnCheck"
      :disable-disable="disableDisable"
      :disable-un-disable="disableUnDisable"
      :disable-close="disableClose"
      @back="backAction"
      @submit="submitAction"
      @check="checkAction"
      @un-check="unCheckAction"
      @rework="reworkAction"
    >
      <div class="card-details">
        <card-view title="基本信息">
          <el-form label-position="top" inline>
            <el-form-item label="单据编号">
              <el-input
                disabled
                v-model="details.codeNo"
                style="width: 280px"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item label="检验类型">
              <el-select
                disabled
                v-model="details.checkType"
                placeholder="请选择"
                clearable
                style="width: 280px"
              >
                <el-option
                  v-for="dict in check_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="生产组织">
              <el-select
                disabled
                v-model="details.productionOrganizationId"
                placeholder="请选择"
                clearable
                style="width: 280px"
              >
                <el-option
                  v-for="dict in sys_organization"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="生产车间">
              <el-select
                disabled
                v-model="details.workshopId"
                placeholder="请选择"
                clearable
                style="width: 280px"
              >
                <el-option
                  v-for="dict in sys_workshop"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="生产人员">
              <el-select
                disabled
                v-model="details.productionUserId"
                placeholder="请选择"
                style="width: 280px"
              >
                <el-option
                  v-for="item in operatorList"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="单据状态">
              <el-select
                disabled
                v-model="details.dataStatus"
                placeholder="请选择"
                clearable
                style="width: 280px"
              >
                <el-option
                  v-for="dict in data_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="校验时间">
              <el-date-picker
                disabled
                style="width: 280px"
                v-model="details.checkedTime"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="业务日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="质检员">
              <el-input
                disabled
                v-model="details.checkUserName"
                style="width: 280px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="工序计划单号">
              <el-input
                disabled
                v-model="details.planCodeNo"
                style="width: 280px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="工序任务单号">
              <el-input
                disabled
                v-model="details.taskCodeNo"
                style="width: 280px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="工序">
              <el-input
                disabled
                v-model="details.processName"
                style="width: 280px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="备注">
              <el-input
                disabled
                v-model="details.remark"
                style="width: 420px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-form>
        </card-view>
        <card-view title="产品信息">
          <template #end>
            <el-button type="primary" link @click="rowAdd">增行</el-button>
            <el-button
              type="primary"
              link
              :disabled="rowIndexList.length != 1"
              @click="rowInsert"
              >插行</el-button
            >
            <el-button
              type="primary"
              link
              :disabled="rowIndexList.length == 0"
              @click="rowDelete"
              >删行</el-button
            >
            <el-button
              type="primary"
              link
              :disabled="rowIndexList.length != 1"
              @click="rowCopy"
              >复制</el-button
            >
          </template>
          <el-table
            :data="tableList"
            border
            @selection-change="handleCheckboxChange"
          >
            <el-table-column type="selection" align="center" width="55" />
            <el-table-column label="序号" align="center" width="80">
              <template #default="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column label="产品编码" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.matterFullCode) }}
              </template>
            </el-table-column>
            <el-table-column label="产品名称" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.matterName) }}
                </div>
                <div v-else>
                  <el-input
                    readonly
                    v-model="scope.row.matterName"
                    placeholder="请输入"
                    @click="matterInputClick(scope.$index, scope.row)"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="助记码" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.matterMnemonicCode) }}
              </template>
            </el-table-column>
            <el-table-column label="规格型号" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.matterSpecModel) }}
              </template>
            </el-table-column>
            <el-table-column label="表面" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.surfaceName) }}
              </template>
            </el-table-column>
            <el-table-column label="批号" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.lotNumber) }}
                </div>
                <div v-else>
                  <el-input
                    v-model="scope.row.lotNumber"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="单轨长度(mm)" align="center" width="180">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.monorailLength) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.monorailLength"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="滑块数量" align="center" width="180">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.sliderNum) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.sliderNum"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="滑块总数量" align="center" width="180">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.sliderAllNum) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.sliderAllNum"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column
              label="导轨销售总长度(mm)"
              align="center"
              width="180"
            >
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.monorailAllLength) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.monorailLength"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="检验数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.checkNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="计量单位" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.unitName) }}
                </div>
                <div v-else>
                  <el-select v-model="scope.row.unitId" placeholder="请选择">
                    <el-option
                      v-for="item in allUnitList"
                      :key="item.id"
                      :label="`${item.name} (${item.fullCode})`"
                      :value="item.id"
                    />
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="辅助数量" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.assistNums) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.assistNums"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="辅助单位" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.assistUnitName) }}
                </div>
                <div v-else>
                  <el-select
                    v-model="scope.row.assistUnitId"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in allUnitList"
                      :key="item.id"
                      :label="`${item.name} (${item.fullCode})`"
                      :value="item.id"
                    />
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="合格数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.passNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="返工数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.reworkNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="让步接收数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.unPassNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="不合格原因" align="center" width="250">
              <template #default="scope">
                <el-input
                  v-model="scope.row.unPassReason"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="废品数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.wasteNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
          </el-table>
        </card-view>
        <card-view title="检验信息">
          <el-table :data="detectionTableList" border>
            <el-table-column label="序号" align="center" width="80">
              <template #default="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column label="检验项目" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkItemName) }}
              </template>
            </el-table-column>
            <el-table-column label="技术指标" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.technicalRequirement) }}
              </template>
            </el-table-column>
            <el-table-column label="检测结果" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkResult) }}
              </template>
            </el-table-column>
            <el-table-column label="判断结果" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.judgeResult) }}
              </template>
            </el-table-column>
            <el-table-column label="检测手段" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkMethod) }}
              </template>
            </el-table-column>
            <el-table-column label="检验方案" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkProgramme) }}
              </template>
            </el-table-column>
            <el-table-column label="检验操作要求" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkOperationRequirement) }}
              </template>
            </el-table-column>
            <el-table-column label="检验标准" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkStandardName) }}
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.remark) }}
              </template>
            </el-table-column>
          </el-table>
        </card-view>
        <card-view title="制单信息">
          <document-view :list="documentList" />
        </card-view>
      </div>
    </manager-view>
    <manager-view
      v-if="viewStatus"
      :show-initiate="false"
      :show-pause="false"
      :show-report="false"
      :show-done="false"
      :show-receive="false"
      :show-get="false"
      :show-first="false"
      :show-roll="details.isLastProcess == '0'"
      :show-qualified-warehousing="details.isLastProcess == '1'"
      :show-waste-storage="details.isLastProcess == '1'"
      :disable-save="disableSave"
      :disable-copy="disableCopy"
      :disable-submit="disableSubmit"
      :disable-cancel="disableCancel"
      :disable-check="disableCheck"
      :disable-un-check="disableUnCheck"
      :disable-disable="disableDisable"
      :disable-un-disable="disableUnDisable"
      :disable-close="disableClose"
      @back="backAction"
      @submit="submitAction"
      @check="checkAction"
      @un-check="unCheckAction"
      @roll="rollAction"
      @qualifiedWarehousing="qualifiedWarehousingAction"
      @wasteStorage="wasteStorageAction"
      @delete="deleteAction"
    >
      <div class="card-details">
        <card-view title="基本信息">
          <el-form label-position="top" inline>
            <el-form-item label="单据编号">
              <el-input
                disabled
                v-model="details.codeNo"
                style="width: 280px"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item label="检验类型">
              <el-select
                disabled
                v-model="details.checkType"
                placeholder="请选择"
                clearable
                style="width: 280px"
              >
                <el-option
                  v-for="dict in check_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="生产组织">
              <el-select
                disabled
                v-model="details.productionOrganizationId"
                placeholder="请选择"
                clearable
                style="width: 280px"
              >
                <el-option
                  v-for="dict in sys_organization"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="生产车间">
              <el-select
                disabled
                v-model="details.workshopId"
                placeholder="请选择"
                clearable
                style="width: 280px"
              >
                <el-option
                  v-for="dict in sys_workshop"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="生产人员">
              <el-select
                disabled
                v-model="details.productionUserId"
                placeholder="请选择"
                style="width: 280px"
              >
                <el-option
                  v-for="item in operatorList"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="单据状态">
              <el-select
                disabled
                v-model="details.dataStatus"
                placeholder="请选择"
                clearable
                style="width: 280px"
              >
                <el-option
                  v-for="dict in data_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="校验时间">
              <el-date-picker
                disabled
                style="width: 280px"
                v-model="details.checkedTime"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="业务日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="质检员">
              <el-input
                disabled
                v-model="details.checkUserName"
                style="width: 280px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="工序计划单号">
              <el-input
                disabled
                v-model="details.planCodeNo"
                style="width: 280px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="工序任务单号">
              <el-input
                disabled
                v-model="details.taskCodeNo"
                style="width: 280px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="工序">
              <el-input
                disabled
                v-model="details.processName"
                style="width: 280px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="备注">
              <el-input
                disabled
                v-model="details.remark"
                style="width: 420px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-form>
        </card-view>
        <card-view title="产品信息">
          <template #end>
            <el-button type="primary" link @click="rowAdd">增行</el-button>
            <el-button
              type="primary"
              link
              :disabled="rowIndexList.length != 1"
              @click="rowInsert"
              >插行</el-button
            >
            <el-button
              type="primary"
              link
              :disabled="rowIndexList.length == 0"
              @click="rowDelete"
              >删行</el-button
            >
            <el-button
              type="primary"
              link
              :disabled="rowIndexList.length != 1"
              @click="rowCopy"
              >复制</el-button
            >
          </template>
          <el-table
            :data="tableList"
            border
            @selection-change="handleCheckboxChange"
          >
            <el-table-column type="selection" align="center" width="55" />
            <el-table-column label="序号" align="center" width="80">
              <template #default="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column label="产品编码" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.matterFullCode) }}
              </template>
            </el-table-column>
            <el-table-column label="产品名称" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.matterName) }}
                </div>
                <div v-else>
                  <el-input
                    readonly
                    v-model="scope.row.matterName"
                    placeholder="请输入"
                    @click="matterInputClick(scope.$index, scope.row)"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="助记码" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.matterMnemonicCode) }}
              </template>
            </el-table-column>
            <el-table-column label="规格型号" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.matterSpecModel) }}
              </template>
            </el-table-column>
            <el-table-column label="表面" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.surfaceName) }}
              </template>
            </el-table-column>
            <el-table-column label="批号" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.lotNumber) }}
                </div>
                <div v-else>
                  <el-input
                    v-model="scope.row.lotNumber"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="单轨长度(mm)" align="center" width="180">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.monorailLength) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.monorailLength"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="滑块数量" align="center" width="180">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.sliderNum) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.sliderNum"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="滑块总数量" align="center" width="180">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.sliderAllNum) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.sliderAllNum"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column
              label="导轨销售总长度(mm)"
              align="center"
              width="180"
            >
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.monorailAllLength) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.monorailLength"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="检验数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.checkNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="计量单位" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.unitName) }}
                </div>
                <div v-else>
                  <el-select v-model="scope.row.unitId" placeholder="请选择">
                    <el-option
                      v-for="item in allUnitList"
                      :key="item.id"
                      :label="`${item.name} (${item.fullCode})`"
                      :value="item.id"
                    />
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="辅助数量" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.assistNums) }}
                </div>
                <div v-else>
                  <el-input
                    type="number"
                    v-no-negative
                    v-model="scope.row.assistNums"
                    placeholder="请输入"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="辅助单位" align="center" width="150">
              <template #default="scope">
                <div v-if="scope.row.isOriginal">
                  {{ blankAttributeDefault(scope.row.assistUnitName) }}
                </div>
                <div v-else>
                  <el-select
                    v-model="scope.row.assistUnitId"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in allUnitList"
                      :key="item.id"
                      :label="`${item.name} (${item.fullCode})`"
                      :value="item.id"
                    />
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="合格数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.passNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="返工数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.reworkNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="让步接收数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.unPassNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="不合格原因" align="center" width="250">
              <template #default="scope">
                <el-input
                  v-model="scope.row.unPassReason"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="废品数量" align="center" width="150">
              <template #default="scope">
                <el-input
                  v-model="scope.row.wasteNums"
                  type="number"
                  placeholder="请输入"
                ></el-input>
              </template>
            </el-table-column>
          </el-table>
        </card-view>
        <card-view title="检验信息">
          <el-table :data="detectionTableList" border>
            <el-table-column label="序号" align="center" width="80">
              <template #default="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column label="检验项目" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkItemName) }}
              </template>
            </el-table-column>
            <el-table-column label="技术指标" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.technicalRequirement) }}
              </template>
            </el-table-column>
            <el-table-column label="检测结果" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkResult) }}
              </template>
            </el-table-column>
            <el-table-column label="判断结果" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.judgeResult) }}
              </template>
            </el-table-column>
            <el-table-column label="检测手段" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkMethod) }}
              </template>
            </el-table-column>
            <el-table-column label="检验方案" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkProgramme) }}
              </template>
            </el-table-column>
            <el-table-column label="检验操作要求" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkOperationRequirement) }}
              </template>
            </el-table-column>
            <el-table-column label="检验标准" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.checkStandardName) }}
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" width="150">
              <template #default="scope">
                {{ blankAttributeDefault(scope.row.remark) }}
              </template>
            </el-table-column>
          </el-table>
        </card-view>
        <card-view title="制单信息">
          <document-view :list="documentList" />
        </card-view>
      </div>
    </manager-view>
    <matter-more-dialog v-model="matterDialog" @selectDone="matterSelectDone" />
  </div>
</template>

<script setup>
import { onMounted, ref } from "vue";
import ManagerView from "@/components/ManagerView/index.vue";
import DocumentView from "@/components/DocumentView/index.vue";
import { useRow } from "@/hooks/row";
import { useRouter } from "vue-router";
import {
    getCheckProcessDetailsApi,
    submitCheckProcessApi,
    checkCheckProcessApi,
    unCheckProcessApi,
    checkProcessTransferOutApi,
    checkProcessGenerateQualifiedApi,
    checkProcessGenerateWasteApi,
    reworkProcessApi, updateCheckProcessApi,
} from "@/api/reportCheck";
import { listOperatorListApi, lisBasicUnitApi } from "@/api/login";
import { blankAttributeDefault } from "@/utils/index";
import MatterMoreDialog from "@/components/CustomDialog/MatterMoreDialog.vue";
import { useLoading } from "@/hooks/loading";
import { useFields } from "@/hooks/fields";

const route = useRoute();
const router = useRouter();

const { proxy } = getCurrentInstance();
const { check_type, sys_organization, sys_workshop, data_status } = toRefs(
  proxy?.useDict(
    "check_type",
    "sys_organization",
    "sys_workshop",
    "data_status"
  )
);

onMounted(() => {
  getCheckDetails(route.query.id);
});

// 检验单详情
const details = ref({});
const detectionTableList = ref([]);
/** 获取检验单详情 */
const getCheckDetails = async (id) => {
  const res = await getCheckProcessDetailsApi(id);
  details.value = res.data;
  details.value.checkType = String(res.data.checkType);
  details.value.dataStatus = String(res.data.dataStatus);
  details.value.productionOrganizationId = String(
    res.data.productionOrganizationId
  );
  detectionTableList.value = res.data.checkProcessInfoList;
  statusJudge(details.value);
  documentInfoCreate(res.data);

  // 产品信息
  tableList.value = details.value.checkProcessMatterList;
  tableList.value.forEach((item) => {
    item.isOriginal = true;
  });
};

const {
  tableList,
  rowIndexList,
  rowAdd,
  rowInsert,
  rowDelete,
  rowCopy,
  handleCheckboxChange,
} = useRow();
const {
  disableSave,
  disableCopy,
  disableSubmit,
  disableCancel,
  disableCheck,
  disableUnCheck,
  disableDisable,
  disableUnDisable,
  disableClose,
  editStatus,
  viewStatus,
  statusJudge,
} = useFields();

const operatorList = ref([]);
/** 获取操作员列表 */
const getOperatorList = async () => {
  const res = await listOperatorListApi();
  operatorList.value = res.data;
};
getOperatorList();

const allUnitList = ref([]);
/** 获取计量单位 */
const getAllUnitList = async () => {
  const res = await lisBasicUnitApi();
  allUnitList.value = res.data;
};
getAllUnitList();

// 选择物料是否点击
const matterDialog = ref(false);
// 当前选择的行
const currentSelectMatterRow = ref({});
// 当前选择的下标
const currentSelectMatterIndex = ref(-1);
/** 物料选择点击 */
const matterInputClick = (index, row) => {
  currentSelectMatterRow.value = row;
  currentSelectMatterIndex.value = index;
  matterDialog.value = true;
};

/** 物料选择完成 */
const matterSelectDone = (matterList) => {
  if (currentSelectMatterRow.value) {
    let matter = matterList[0];
    currentSelectMatterRow.value.matterId = matter.id;
    currentSelectMatterRow.value.matterFullCode = matter.fullCode;
    currentSelectMatterRow.value.matterName = matter.name;
    currentSelectMatterRow.value.matterMnemonicCode = matter.mnemonicCode;
    currentSelectMatterRow.value.matterSpecModel = matter.specModel;
    currentSelectMatterRow.value.surfaceId = matter.surfaceId;
    currentSelectMatterRow.value.surfaceName = matter.surfaceName;

    // 其他的插入后续位置
    for (let i = 1; i < matterList.length; i++) {
      let item = matterList[i];
      let otherMatter = {};
      otherMatter.isOriginal = false;
      otherMatter.matterId = item.id;
      otherMatter.matterFullCode = item.fullCode;
      otherMatter.matterName = item.name;
      otherMatter.matterMnemonicCode = item.mnemonicCode;
      otherMatter.matterSpecModel = item.specModel;
      otherMatter.surfaceId = item.surfaceId;
      otherMatter.surfaceName = item.surfaceName;
      tableList.value.splice(
        currentSelectMatterIndex.value + i,
        0,
        otherMatter
      );
    }
  }
};

const { loading, close } = useLoading();

/**
 * 保存
 */
// const saveAction = async () => {
//     loading("加载中");
//     try {
//         let dto: any = [];
//         tableList.value.forEach((item) => {
//             dto.push({
//                 checkNums:item.checkNums,
//                 passNums:item.passNums,
//                 reworkNums:item.reworkNums,
//                 unPassNums:item.unPassNums,
//                 unPassReason:item.unPassReason,
//                 wasteNums:item.wasteNums
//             });
//         });
//         const res = await updateCheckProcessApi(details.value.id,tableList.value);
//         getCheckDetails(details.value.id);
//         close();
//     } catch (err) {
//         close();
//     }
// }


/** 提交 */
const submitAction = async () => {
  loading("加载中");
  try {
    const res = await submitCheckProcessApi(details.value.id);
    getCheckDetails(details.value.id);
    ElMessage.success('提交成功');
    close();
  } catch (err) {
      ElMessage.error('提交失败'+err);
    close();
  }
};
/** 删除 */
const deleteAction = async () => {
  loading("删除中");
  try {
    const res = await delCheckProcessApi(details.value.id);
    close();
    backAction();
  } catch (err) {
    close();
  }
};

/** 审核 */
const checkAction = async () => {
  loading("加载中");
  try {
    const res = await checkCheckProcessApi(details.value.id);
    getCheckDetails(details.value.id);
    close();
  } catch (err) {
    close();
  }
};

/** 反审核 */
const unCheckAction = async () => {
  loading("加载中");
  try {
    const res = await unCheckProcessApi(details.value.id);
    getCheckDetails(details.value.id);
    close();
  } catch (err) {
    close();
  }
};

/** 返工*/
const reworkAction = async () => {
  loading("加载中");
  try {
    const res = await reworkProcessApi(details.value.id);
    getCheckDetails(details.value.id);
    close();
  } catch (err) {
    close();
  }
};

/** 转出 */
const rollAction = async () => {
  if (rowIndexList.value.length == 0) {
    ElMessage.error("请选择产品");
  } else {
    let idList = rowIndexList.value.map((item) => {
      return item.row.id;
    });
    let dic = {
      id: details.value.id,
      checkProcessMatterIdList: idList,
    };
    loading("加载中");
    try {
      await checkProcessTransferOutApi(dic);
      getCheckDetails(details.value.id);
      close();
    } catch (error) {
      close();
    }
  }
};

/** 合格入库 */
const qualifiedWarehousingAction = async () => {
  if (rowIndexList.value.length == 0) {
    ElMessage.error("请选择产品");
  } else {
    let idList = rowIndexList.value.map((item) => {
      return item.row.id;
    });
    let dic = {
      id: details.value.id,
      checkProcessMatterIdList: idList,
    };
    loading("加载中");
    try {
      await checkProcessGenerateQualifiedApi(dic);
      getCheckDetails(details.value.id);
      close();
    } catch (error) {
      close();
    }
  }
};

/** 废品入库 */
const wasteStorageAction = async () => {
  if (rowIndexList.value.length == 0) {
    ElMessage.error("请选择产品");
  } else {
    let idList = rowIndexList.value.map((item) => {
      return item.row.id;
    });
    let dic = {
      id: details.value.id,
      checkProcessMatterIdList: idList,
    };
    loading("加载中");
    try {
      await checkProcessGenerateWasteApi(dic);
      getCheckDetails(details.value.id);
      close();
    } catch (error) {
      close();
    }
  }
};

/** 制单信息 */
const documentList = ref([]);
const documentInfoCreate = (details) => {
  let list = [];
  // 制单人
  let cteateInfo = {
    titleTop: "制单人",
    infoTop: details?.createName,
    titleBottom: "创建时间",
    infoBottom: details?.createTime,
  };
  list.push(cteateInfo);

  // 修改人
  let updateInfo = {
    titleTop: "修改人",
    infoTop: details?.updateName,
    titleBottom: "修改时间",
    infoBottom: details?.updateTime,
  };
  list.push(updateInfo);

  // 审核人
  let checkInfo = {
    titleTop: "审核人",
    infoTop: details?.checkName,
    titleBottom: "审核时间",
    infoBottom: details?.checkTime,
  };
  list.push(checkInfo);
  documentList.value = list;
};
documentInfoCreate();

/** 返回 */
const backAction = () => {
  console.log(123);
  router.go(-1);
};
</script>

<style lang="scss" scoped>
@include edit-table;
</style>
